package zhklappoint.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import zhklappoint.dao.DrainageDao;
import zhklappoint.entity.DrainageObj;
import zhklappoint.entity.FunctionKinds;
import zhklappoint.enums.ENUM_ISDELETE;
import zhklappoint.service.DrainageService;
import zhklappoint.util.PageUtils;

@Service
public class DrainageServiceImpl implements DrainageService{

	@Autowired
	private DrainageDao drainageDao;
	
	
	@Override
	public DrainageObj saveDrainageObj(DrainageObj drainage) {
		return drainageDao.save(drainage);
	}

	@Override
	public Page<DrainageObj> getDrainageObj(DrainageObj drainage, Integer page, Integer size) {
		drainage.setIsdelete(ENUM_ISDELETE.NOT_DELETED.value);
        Pageable pageable= PageUtils.toPageable(page, size, Sort.Direction.DESC, "createdate");
        ExampleMatcher matcher=ExampleMatcher.matching()
                .withMatcher("isdelete", ExampleMatcher.GenericPropertyMatchers.exact())
                .withIgnorePaths("createdate","updatedate");// 忽略字段，即不管忽略名字是什么值都不加入查询条件
        Example<DrainageObj> example = Example.of(drainage, matcher);
        return drainageDao.findAll(example, pageable);
	}
	
}
